(function ($)
{
	

	//扩展一个 多行文本框 的编辑器
	        $.ligerDefaults.Grid.editors['textarea'] = {
	            create: function (container, editParm)
	            {
	                var input = $("<textarea />");
	                container.append(input);
	                return input;
	            },
	            getValue: function (input, editParm)
	            {
	                return input.val();
	            },
	            setValue: function (input, value, editParm)
	            {
	                input.val(value);
	            },
	            resize: function (input, width, height, editParm)
	            {
	                var column = editParm.column; 
	                if (column.editor.width) input.width(column.editor.width);
	                else input.width(width);
	                if (column.editor.height) input.height(column.editor.height);
	                else input.height(height);
	            }
	        };
	        
	        
	        /**
	         * 扩展一个 通过后台获取数据的下拉列表 的编辑器
	         */
	         $.ligerDefaults.Grid.editors['selecturl'] =
	             $.ligerDefaults.Grid.editors['combobox'] =
	             {
	                 create: function (container, editParm)
	                 {
	                     getUrlData(editParm.column.editor.path ,editParm.record.materialsid);
	                     var column = editParm.column;
	                     $("#"+editParm.column.editor.dataItem).val(JSON.stringify(result));
	                     var input = $("<input type='text'/>");
	                     container.append(input);
	                     var options = {   
	                         data:  result,
	                         slide: false,
	                         valueField: column.editor.valueField || column.editor.valueColumnName,
	                         textField: column.editor.textField || column.editor.displayColumnName
	                     };
	                     var ext = column.editor.p || column.editor.ext;
	                     if (ext)
	                     {
	                         var tmp = typeof (ext) == 'function' ?
	                         ext(editParm.record, editParm.rowindex, editParm.value, column) : ext;
	                         $.extend(options, tmp);
	                     }
	                     input.ligerComboBox(options);
	                     return input;
	                 },
	                 getValue: function (input, editParm)
	                 {
	                     return input.liger('option', 'value');
	                 },
	                 setValue: function (input, value, editParm)
	                 {
	                     input.liger('option', 'value', value);
	                 },
	                 resize: function (input, width, height, editParm)
	                 {
	                     input.liger('option', 'width', width);
	                     input.liger('option', 'height', height);
	                 },
	                 destroy: function (input, editParm)
	                 {
	                     input.liger('destroy');
	                 }
	             };
	         
	         
	         $.ligerDefaults.Grid.editors['date1'] =
	         {
	             create: function (container, editParm)
	             {
	                 var column = editParm.column;
	                 var input = $('<input type="text" onclick="WdatePicker({dateFmt:\'yyyy-MM-dd\'})"  readonly="readonly"/>');
	                 container.append(input);
	                 //input.ligerDateEditor(options);
	                 return input;
	             },
	             getValue: function (input, editParm)
	             { 
	                 return input.liger('option', 'value');
	             },
	             setValue: function (input, value, editParm)
	             { 
	                 input.liger('option', 'value', value);
	             },
	             resize: function (input, width, height, editParm)
	             {
	                 input.liger('option', 'width', width);
	                 input.liger('option', 'height', height);
	             },
	             destroy: function (input, editParm)
	             {
	                 input.liger('destroy');
	             }
	  };  
	         $.ligerDefaults.Grid.editors['scdate'] =
	 	     {
	 	         create: function (container, editParm)
	 	         {
	 	             var input = $('<input type="text" id="scdate" onclick="WdatePicker({dateFmt:\'yyyy-MM-dd\'})"  readonly="readonly"/>');
	 	             container.append(input);
	 	             input.ligerTextBox();
	 	             return input;
	 	         },
	 	         getValue: function (input, editParm)
	 	         { 
	 	     		return input.val();
	 	         },
	 	         setValue: function (input, value, editParm)
	 	         {
	 	             input.val(value);
	 	         },
	 	         resize: function (input, width, height, editParm)
	 	         {
	 	             input.liger('option', 'width', width);
	 	             input.liger('option', 'height', height);
	 	         },
	 	         destroy: function (input, editParm)
	 	         {
	 	             input.liger('destroy');
	 	         }
	 	     }; 
	        
	         /**
	          * 扩展一个 通过后台获取批次的下拉列表 的编辑器
	          */
	          $.ligerDefaults.Grid.editors['selectbatch'] =
	              $.ligerDefaults.Grid.editors['combobox'] =
	              {
	                  create: function (container, editParm)
	                  {
	                 	 var result = [];
	                 	 $.ajax({
	                 			      url: editParm.column.editor.path,
	                 			      global: false,
	                 			      type: "POST",
	                 			      async:false,
	                 			      dataType: "json",
	                 			      data: ({
	                 			    	  maCode:editParm.record.code,
	                 			    	  whCode:$("#"+editParm.column.editor.whcode).val(),
	                 			    	  hubCode:editParm.record.hubCode==null?'':editParm.record.hubCode
	                 			      }),		     
	                 			      success: function(msg){
	                 			    	 result = msg;
	                 			      }
	                 	 });
	                      var column = editParm.column;
	                      $("#"+editParm.column.editor.databatch).val(JSON.stringify(result));
	                      var input = $("<input type='text'/>");
	                      container.append(input);
	                      var options = {   
//	                          data:  result,
//	                          slide: false,
//	                          valueField: column.editor.valueField || column.editor.valueColumnName,
//	                          textField: column.editor.textField || column.editor.displayColumnName
	                      };
	                      var ext = column.editor.p || column.editor.ext;
	                      if (ext)
	                      {
	                          var tmp = typeof (ext) == 'function' ?
	                          ext(editParm.record, editParm.rowindex, editParm.value, column) : ext;
	                          $.extend(options, tmp);
	                      }
	                      input.ligerComboBox(options);
	                      return input;
	                  },
	                  getValue: function (input, editParm)
	                  {
	                      return input.liger('option', 'value');
	                  },
	                  setValue: function (input, value, editParm)
	                  {
	                      input.liger('option', 'value', value);
	                  },
	                  resize: function (input, width, height, editParm)
	                  {
	                      input.liger('option', 'width', width);
	                      input.liger('option', 'height', height);
	                  },
	                  destroy: function (input, editParm)
	                  {
	                      input.liger('destroy');
	                  }
	              };
	          
	          //======================
	 /**
	  * 新增添加Grid的添加行方法，修正总计记录数量不对的bug
	  * @author huang.xuming [2013-09-24]
	  */
	 $.ligerui.controls.Grid.prototype.addRow2=function (rowdata, neardata, isBefore, parentRowData){
	 	var g = this;
	 	g.addRow(rowdata, neardata, isBefore, parentRowData);
	 	g.options.total = g.getData.length;
	 	g.reRender();
	 };
	         
})(jQuery);

        
        
   var result = [];
   function getUrlData(path ,data){
	   $.ajax({
		      url: path,
		      global: false,
		      type: "POST",
		      async:false,
		      dataType: "json",
		      data: ({
		    	   id:data 
		      }),		     
		      success: function(msg){
		    	 result = msg;
		      }
	   });
   }
        

        
